<?php
App::uses('AppModel', 'Model');
/**
 * User Model
 *
 * @property Contact $Contact
 * @property Note $Note
 * @property Timesheet $Timesheet
 * @property Team $Team
 */
class User extends AppModel {

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'username';

/**
 * Validation rules
 *
 * @var array
 */
    public $validate = array(
        'username' => array(
            'notempty' => array(
                'rule' => array('notEmpty'),
                'message'=> 'Please enter a username.',
            ),
            'unique_id'=> array(
                'rule'=> 'isUnique',
                'message'=> 'User ID already exists. Please choose a different ID.',
            ),
            'letters_numbers'=> array(
                'rule'=> 'alphaNumeric',
                'message'=> 'Only letters and numbers allowed.',
            ),
            'character_length'=> array(
                'rule' => array('minLength', 4),
                'message' => 'Minimum length of 4 characters must be entered.'
            )
        ),
        'password' => array(
            'notempty' => array(
                'rule' => array('notEmpty'),
            ),
            'Match passwords'=>array(
                'rule'=> 'matchPasswords',
                'message'=>'Your passwords do not match'
            ),
            'character_length'=> array(
                'rule' => array('minLength', 4),
                'message' => 'Minimum length of 4 characters must be entered.'
            )
        ),
        'password_confirmation'=>array(
            'Not empty' =>array(
                'rule'=>'notEmpty',
                'message'=>'Please enter your password again'
            ),
        ),
        'contact_id' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'permission' => array(
            'numeric' => array(
                'rule' => array('numeric'),
                //'message' => 'Your custom message here',
                //'allowEmpty' => false,
                //'required' => false,
                //'last' => false, // Stop validation after this rule
                //'on' => 'create', // Limit validation to 'create' or 'update' operations
            ),
        ),
        'start_date' => array(
            'date' => array(
                'rule' => array('date'),
            ),
            'startEnd'=> array(
                'rule' => 'startDateGreaterEndDate',
                'message' => 'Start date cannot be greater than end date.'
            )
        ),
        'end_date' => array(
            'date' => array(
                'rule' => array('date'),
            ),
        ),
	);

	//The Associations below have been created with all possible keys, those that are not needed can be removed

/**
 * belongsTo associations
 *
 * @var array
 */
	public $belongsTo = array(
		'Contact' => array(
			'className' => 'Contact',
			'foreignKey' => 'contact_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

/**
 * hasMany associations
 *
 * @var array
 */
	public $hasMany = array(
		'Note' => array(
			'className' => 'Note',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		),
		'Timesheet' => array(
			'className' => 'Timesheet',
			'foreignKey' => 'user_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);


/**
 * hasAndBelongsToMany associations
 *
 * @var array
 */
	public $hasAndBelongsToMany = array(
		'Team' => array(
			'className' => 'Team',
			'joinTable' => 'teams_users',
			'foreignKey' => 'user_id',
			'associationForeignKey' => 'team_id',
			'unique' => 'keepExisting',
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		)
	);

}
